package net.xdclass.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import net.xdclass.manager.ShortLinkManager;
import net.xdclass.mapper.ShortLinkMapper;
import net.xdclass.model.ShortLinkDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
public class ShortLinkManagerImpl implements ShortLinkManager {
    @Autowired
	private ShortLinkMapper shortLinkMapper;

	@Override
	public int addShortLink(ShortLinkDO shortLinkDO) {
		return shortLinkMapper.insert(shortLinkDO);
	}

	@Override
	public ShortLinkDO findByShortLinkCode(String shortLinkCode) {
		return shortLinkMapper.selectOne(new QueryWrapper<ShortLinkDO>().eq("code",shortLinkCode));
	}

	@Override
	public int del(String shortLinkCode, Long accountNo) {
		return shortLinkMapper.delete(new QueryWrapper<ShortLinkDO>().eq("code",shortLinkCode)
		.eq("account_no",accountNo));
	}

	@Override
	public int update(ShortLinkDO shortLinkDO) {
		return shortLinkMapper.update(null,new UpdateWrapper<ShortLinkDO>()
				.eq("code", shortLinkDO.getCode())
				.eq("del", 0)
				.eq("account_no",shortLinkDO.getAccountNo())
				.set("title", shortLinkDO.getTitle())
				.set("domain", shortLinkDO.getDomain()));
	}
}
